import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
	{
		path: "/",
		redirect: "/login",
	},
	{
		path: "/login",
		name: "Login",
		// 懒加载组件，不需要import导入再放到路由对象中，直接使用函数懒加载引入对应的组件
		component: () => import(/* webpackChunkName: "about" */ "../views/Login.vue"),
	},
	{
		path: "/licence",
		name: "Licence",
		component: () => import(/* webpackChunkName: "about" */ "../views/licence/Licence.vue"),
	},
	{
		path: "/changeUserPassword",
		name: "ChangeUserPassword",
		component: () => import(/* webpackChunkName: "about" */ "../views/common/ChangeUserPassword.vue"),
	},
	// {
	// 	path: "/mainMap",
	// 	name: "MainMap",
	// 	component: () => import(/* webpackChunkName: "about" */ "../views/MainMap.vue"),
	// },
	{
		path: "/mapScreen",
		name: "MapNode",
		component: () => import(/* webpackChunkName: "about" */ "../views/common/MapNode.vue"),
	},
	{
		path: "/mapScreenSecond",
		name: "MapNode2",
		component: () => import(/* webpackChunkName: "about" */ "../views/common/MapNode2.vue"),
	},
	{
		path: "/monitoring",
		name: "Monitoring",
		component: () => import(/* webpackChunkName: "about" */ "../views/division/monitoring/Monitoring.vue"),
	},
	{
		path: "/mapCoord",
		name: "MapCoord",
		component: () => import(/* webpackChunkName: "about" */ "../views/division/terminal/MapCoord.vue"),
	},
	{
		path: "/index",
		name: "Index",
		meta:{
			//需要登录后才能访问
			requiresAuth:true
		},
		component: () => import(/* webpackChunkName: "about" */ "../views/Index.vue"),
		// redirect: "/index/main",
		children: [
			{
				path: "/index/main",
				name: "ControlIndex",
				component: () => import(/* webpackChunkName: "about" */ "../views/division/control/ControlIndex.vue"),
			},
			{
				path: "/index/terminal",
				name: "TerminalIndex",
				component: () => import(/* webpackChunkName: "about" */ "../views/division/terminal/TerminalIndex.vue"),
			},
			{
				path: "/index/character",
				name: "CharacterIndex",
				component: () => import(/* webpackChunkName: "about" */ "../views/division/character/CharacterIndex.vue"),
				children: [
					{
						path: "/index/character/character_keyword",
						name: "CharacterKeyword",
						component: () => import(/* webpackChunkName: "about" */ "../views/division/character/configuration/CharacterKeyword.vue"),
					},
					{
						path: "/index/character/character_repertoire",
						name: "CharacterRepertoire",
						component: () => import(/* webpackChunkName: "about" */ "../views/division/character/configuration/CharacterRepertoire.vue"),
					},
				],
			},
			{
				path: "/index/imglibrary",
				name: "ImgLibraryIndex",
				component: () => import(/* webpackChunkName: "about" */ "../views/division/imglibrary/ImgLibraryIndex.vue"),
				children: [
					{
						path: "/index/character/imglibrary_keyword",
						name: "ImgLibraryKeyword",
						component: () => import(/* webpackChunkName: "about" */ "../views/division/imglibrary/configuration/ImgLibraryKeyword.vue"),
					},
				],
			},
			{
				path: "/index/strategy",
				name: "StrategyIndex",
				component: () => import(/* webpackChunkName: "about" */ "../views/division/strategy/StrategyIndex.vue"),
				children: [
					{
						path: "/index/strategy/strategy_manage",
						name: "StrategyManage",
						component: () => import(/* webpackChunkName: "about" */ "../views/division/strategy/configuration/StrategyManage.vue"),
					},
					{
						path: "/index/strategy/strategy_img",
						name: "StrategyImg",
						component: () => import(/* webpackChunkName: "about" */ "../views/division/strategy/configuration/StrategyImg.vue"),
					},
					{
						path: "/index/strategy/strategy_voltage",
						name: "StrategyVoltage",
						component: () => import(/* webpackChunkName: "about" */ "../views/division/strategy/configuration/StrategyVoltage.vue"),
					},
					// {
					// 	path: "/index/strategy/strategy_keyword",
					// 	name: "StrategyKeyword",
					// 	component: () => import(/* webpackChunkName: "about" */ "../views/division/strategy/configuration/StrategyKeyword.vue"),
					// },
					{
						path: "/index/strategy/strategy_safety",
						name: "StrategySafety",
						component: () => import(/* webpackChunkName: "about" */ "../views/division/strategy/configuration/StrategySafety.vue"),
					},
					{
						path: "/index/strategy/strategy_overall",
						name: "StrategyOverall",
						component: () => import(/* webpackChunkName: "about" */ "../views/division/strategy/configuration/StrategyOverall.vue"),
					},
				],
			},
			{
				path: "/index/issueflow",
				name: "IssueflowIndex",
				component: () => import(/* webpackChunkName: "about" */ "../views/division/issueflow/IssueflowIndex.vue"),
			},
			{
				path: "/index/realtime",
				name: "RealtimeIndex",
				component: () => import(/* webpackChunkName: "about" */ "../views/division/realtime/RealtimeIndex.vue"),
			},
			{
				path: "/index/simHistory",
				name: "SimHistory",
				component: () => import(/* webpackChunkName: "about" */ "../views/division/sim/SimHistory.vue"),
			},
			{
				path: "/index/audit",
				name: "AuditIndex",
				component: () => import(/* webpackChunkName: "about" */ "../views/division/audit/AuditIndex.vue"),
			},
			{
				path: "/index/inside",
				name: "InsideIndex",
				component: () => import(/* webpackChunkName: "about" */ "../views/division/inside/InsideIndex.vue"),
			},
			{
				path: "/index/approveLog",
				name: "ApproveLog",
				component: () => import(/* webpackChunkName: "about" */ "../views/division/approvelog/ApproveLog.vue"),
			},
			{
				path: "/index/admittance",
				name: "AdmittanceIndex",
				component: () => import(/* webpackChunkName: "about" */ "../views/division/admittance/AdmittanceIndex.vue"),
			},
			{
				path: "/index/workorder",
				name: "WorkorderIndex",
				component: () => import(/* webpackChunkName: "about" */ "../views/division/workorder/WorkOrderIndex.vue"),
			},
			// {
			// 	path: "/index/safety",
			// 	name: "SafetyIndex",
			// 	component: () => import(/* webpackChunkName: "about" */ "../views/division/safety/SafetyIndex.vue"),
			// },
			{
				path: "/index/syslog",
				name: "syslogIndex",
				component: () => import(/* webpackChunkName: "about" */ "../views/division/syslog/SyslogIndex.vue"),
			},
			{
				path: "/index/system",
				name: "SystemIndex",
				component: () => import(/* webpackChunkName: "about" */ "../views/division/system/SystemIndex.vue"),
				children: [
					{
						path: "/index/system/system_state",
						name: "SystemState",
						component: () => import(/* webpackChunkName: "about" */ "../views/division/system/configuration/SystemState.vue"),
					},
					{
						path: "/index/system/system_network",
						name: "SystemNetwork",
						component: () => import(/* webpackChunkName: "about" */ "../views/division/system/configuration/SystemNetwork.vue"),
					},
					// {
					// 	path: "/index/system/system_parameter",
					// 	name: "SystemParameter",
					// 	component: () => import(/* webpackChunkName: "about" */ "../views/division/system/configuration/SystemParameter.vue"),
					// },
					{
						path: "/index/system/system_user",
						name: "SystemUser",
						component: () => import(/* webpackChunkName: "about" */ "../views/division/system/configuration/SystemUser.vue"),
					},
					{
						path: "/index/system/system_role",
						name: "SystemRole",
						component: () => import(/* webpackChunkName: "about" */ "../views/division/system/configuration/SystemRole.vue"),
					},
					{
						path: "/index/system/system_control",
						name: "SystemControl",
						component: () => import(/* webpackChunkName: "about" */ "../views/division/system/configuration/SystemControl.vue"),
					},
					{
						path: "/index/system/system_firmware",
						name: "SystemFirmware",
						component: () => import(/* webpackChunkName: "about" */ "../views/division/system/configuration/SystemFirmware.vue"),
					},
					{
						path: "/index/system/system_logstore",
						name: "SystemLogStore",
						component: () => import(/* webpackChunkName: "about" */ "../views/division/system/configuration/SystemLogStore.vue"),
					},
					{
						path: "/index/system/system_backupAndRestore",
						name: "SystemBackupAndRestore",
						component: () => import(/* webpackChunkName: "about" */ "../views/division/system/configuration/SystemBackupAndRestore.vue"),
					},
					{
						path: "/index/system/system_about",
						name: "SystemAbout",
						component: () => import(/* webpackChunkName: "about" */ "../views/division/system/configuration/SystemAbout.vue"),
					},
				],
			},
		],
	},
];

const router = new VueRouter({
	mode: "history",
	base: process.env.BASE_URL,
	routes,
});

//路由拦截
router.beforeEach((to, from, next) => {
	//判断是否是登录保护路由
	if (to.matched.some(record => record.meta.requiresAuth)) {
		//验证浏览器本地存储是否有token（或从vuex、Cookie、localStorage中获取，依据自己的存储），用于判断是否登录
		if (!localStorage.token) {//没有token，表示未登录，则重定向到login
			next({
				//这里是你登录页面的路由名称，或直接使用 path:'/login'
				name: 'Login',
				query: {redirect: to.fullPath}
			})
		} else {
			next()
		}
	} else {
		// 确保一定要调用 next()
		next()
	}
});

export default router;
